package com.ruoyi.project.system.mapper;

import com.ruoyi.project.system.domain.Course;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 课程Mapper接口
 * 
 * @author ruoyi
 * @date 2020-10-07
 */
public interface CourseMapper 
{
    /**
     * 查询课程
     * 
     * @param id 课程ID
     * @return 课程
     */
    public Course selectCourseById(Integer id);

    /**
     * 查询课程列表
     * 
     * @param course 课程
     * @return 课程集合
     */
    public List<Course> selectCourseList(Course course);

    /**
     * 新增课程
     * 
     * @param course 课程
     * @return 结果
     */
    public int insertCourse(Course course);

    /**
     * 修改课程
     * 
     * @param course 课程
     * @return 结果
     */
    public int updateCourse(Course course);

    /**
     * 删除课程
     * 
     * @param id 课程ID
     * @return 结果
     */
    public int deleteCourseById(Integer id);

    /**
     * 批量删除课程
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    public int deleteCourseByIds(Integer[] ids);


    @Select("select title as name,resource_url as url,id from course where course_catalog_id = #{course_catalog_id} order by sequence")
    List<Map<String, Object>> deleteCourseByCatalogId(@Param("course_catalog_id") Long id);

    @Select("select COALESCE(sum(count), 0)  from course")
    int selectSumCount();

    @Select("select title from course ORDER BY count desc  limit 10 offset 0 ")
    List<String> selectCourseName();

    @Select("select COALESCE(count, 0)  from course ORDER BY count desc limit 10 offset 0")
    List<Integer> selectCourseCount();

    @Select("select COALESCE(sum(1), 0) from course_study where college_id=#{college_id}")
    int selectSumCountCollegeId(@Param("college_id") Long deptId);

    @Select("select course_title from course_study where college_id=#{college_id} GROUP BY course_title ORDER BY course_title ASC  limit 10 offset 0 ")
    List<String> selectCourseNameCollegeId(@Param("college_id") Long deptId);

    @Select("select count(course_id) from course_study where college_id=#{college_id}  GROUP BY course_id ORDER BY course_id ASC  limit 10 offset 0")
    List<Integer> selectCourseCountCollegeId(@Param("college_id") Long deptId);

    /**
     * 微信小程序页面获取课程信息
     * @return
     */
    List<Course> getCourseInfoList(Course course);
}
